package com.itheima.order;

import com.itheima.feign.client.UserClient;
import com.itheima.feign.config.FeignConfig;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@MapperScan("com.itheima.order.mapper")
@SpringBootApplication
//@EnableFeignClients //开启feign支持
//@EnableFeignClients(defaultConfiguration = FeignConfig.class) //指定使用哪个配置类
//@EnableFeignClients(basePackages = "com.itheima.feign.client")//扫描指定包下的client，创建代理对象，放入spring容器中
@EnableFeignClients(clients = {UserClient.class})//创建指定的client的代理对象，放入spring容器中
public class OrderApplication {

    public static void main(String[] args) {
        SpringApplication.run(OrderApplication.class, args);
    }

    @Bean  //必须放在配置类中
    @LoadBalanced  //配置负载均衡，开启负载均衡
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    //修改全局负载均衡策略
   // @Bean
    public IRule iRule(){
        return new RandomRule();
    }
}